package com.nc.delivery_project.server.dao;

import com.nc.delivery_project.server.domain.LegalPerson;

import java.sql.*;

/**
 * Created by miroshnik on 1/23/2015.
 */
public class LegalPersonDao extends PersonDao<LegalPerson> {

    public static final String ENTITY_NAME = LegalPerson.class.getSimpleName();
    public static final String TITLE = "TITLE";

    public LegalPersonDao() {
        super(ENTITY_NAME);
    }

    public LegalPersonDao(Connection connection) throws SQLException {
        super(connection, ENTITY_NAME);
    }

    public LegalPersonDao(Connection connection, String entityName) throws SQLException {
        super(connection, entityName);
    }

    @Override
    protected void doPrepareInsertStatement(CallableStatement statement, LegalPerson object) throws SQLException {
        statement.setString(4, object.getTitle());
        statement.setInt(1, object.getLegalPersonId());
    }

    @Override
    protected void doPrepareUpdateStatement(CallableStatement statement, LegalPerson object) throws SQLException {
        statement.setInt(1, object.getLegalPersonId());
        statement.setString(4, object.getTitle());
    }

    @Override
    protected LegalPerson parsePerson(ResultSet rs) throws SQLException {
        int personId = rs.getInt(PERSON_ID);
        int userId = rs.getInt(USER_ID);
        String title = rs.getString(TITLE);
        return new LegalPerson(userId, personId, title);
    }
}
